# encoding: utf-8
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

from ..config.base import MODEL_SAVE_PATH, ORIGIN_MODEL_NAME, ORIGIN_TASK, ORIGIN_MODEL_PATH, CONTRACT_MODEL_DEVICE


def create_origin_model():
    task = 'rex-uninlu'
    if ORIGIN_MODEL_NAME == 'nlp_deberta_rex-uninlu_chinese-base':
        task = 'rex-uninlu'
    semantic_cls = pipeline(task=task, model=ORIGIN_MODEL_PATH, batch_size=2)
    return semantic_cls


def create_model(model_path, task):
    semantic_cls = pipeline(task=task, model=model_path)
    return semantic_cls


def create_model_with_name(model_name, task=ORIGIN_TASK):
    if model_name is None or model_name == '0':
        model_path = ORIGIN_MODEL_PATH
    else:
        model_path = MODEL_SAVE_PATH + '//' + model_name + '//' + ORIGIN_MODEL_NAME
    semantic_cls = pipeline(task=task, model=model_path, device=CONTRACT_MODEL_DEVICE)
    return semantic_cls
